package com.zetyun.tiger.format.trim;


import com.zetyun.rt.meta.annotation.ActionMeta;
import com.zetyun.rt.sdk.action.MapAction;
import com.zetyun.rt.sdk.model.RtEvent;

@ActionMeta(
        id = "tiger.trim-value",
        tags = {"formatter"},
        category = "map",
        name = "TrimValue",
        description = "对RtEvent里面的字符串值进行trim操作"
)
public class TrimAction extends MapAction {

    @Override
    public RtEvent apply(RtEvent rtEvent) throws Exception {

        //对rtEvent的数据进行trim操作
        rtEvent.getFields().forEach((key, value) -> {
            if (value != null) {
                if (value instanceof String) {
                    rtEvent.setField(key, value.toString().trim());
                }
            }
        });

        return rtEvent;
    }
}
